package com.foreknow.service.impl;

import com.foreknow.bean.Admin;
import com.foreknow.dao.AdminDao;
import com.foreknow.dao.impl.AdminDaoImpl;
import com.foreknow.db.DBManager;
import com.foreknow.db.JdbcTemplate;
import com.foreknow.service.AdminService;

import java.sql.Connection;
import java.sql.SQLException;

public class AdminServiceImpl implements AdminService {
    @Override
    public Admin isValidate(String adminName, String password) {
        DBManager dbManager = DBManager.getInstance();
        Connection conn = dbManager.getConnection();
        JdbcTemplate jdbcTemplate = JdbcTemplate.getInstance();
        //将DBManager中的conn传递到JdbcTemplate中的conn,才能对数据库操作
        jdbcTemplate.setConnection(conn);
        AdminDao adminDao = new AdminDaoImpl();
        Admin admin = null;
        try {
            admin = adminDao.getAdminByNameByPass(adminName,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return admin;
    }
}
